{literal}
<script type="text/javascript">
function deleteObject(id) {
	$('td.selAll input[type=checkbox]').attr('checked',false);
	$('#remove_' + id).attr('checked','checked');
	return deleteObjects(false);
}

function deleteObjects(check) {
//	if(check == undefined || check == null)
	    check = true;

	var ids = [];

	$('td.selAll input[type=checkbox]').each(function(){
		if($(this).attr('checked')) {
			ids[ids.length] = $(this).val();
		};
	});

	
	
	if(ids.length > 0 && check?confirm('Czy na pewno chcesz usunąć wybrane elementy z listy?'):true) {
		$.post('{/literal}{url User=AjaxRemoveUsers}{literal}',{'ids[]':ids},function(data){
			window.location.reload(true);
		});
	}
	return false;
}

function statusObject(obj) {
	$(obj).attr('disabled','disabled');
	var ids = [$(obj).val()];
	$.post('{/literal}{url User=AjaxBlockUsers}{literal}',{'ids[]':ids},function(data){
		$(obj).attr('disabled',false);
	});

}


function activeObject(obj) {
	$(obj).attr('disabled','disabled');
	var ids = [$(obj).val()];
	$.post('{/literal}{url User=AjaxActiveUsers}{literal}',{'ids[]':ids},function(data){
		$(obj).attr('disabled',false);
	});

}

function blockObjects() {
	var ids = [];


	$('td.selAll input[type=checkbox]').each(function(){
		if($(this).attr('checked')) {
			ids[ids.length] = $(this).val();
		};
	});

	
	
	if(ids.length > 0 && confirm('Czy na pewno chcesz zablokować wybrane elementy z listy?')) {
		$('.status').attr('disabled','disabled');
		$.post('{/literal}{url User=AjaxBlockUsers}{literal}',{'ids[]':ids, 'block' : 1},function(data){
			window.location.reload(true);
		});
	}
	return false;
}

function confirmAction(obj, urlValue)
{
	$(obj).attr('disabled', 'disabled');
	$(obj).parent().parent().find('input[type="checkbox"]').attr('disabled', 'disabled');
	var r = confirm($(obj).attr('title'));
	if(r == true)
	{
		$.ajax({
			url: urlValue,
			type: 'GET',
			success: function(){
				window.location.reload(true);
			}
		});
	} else {
		$(obj).removeAttr('disabled');
		$(obj).parent().parent().find('input[type="checkbox"]').removeAttr('disabled');
		
	}
	return false;
}

function toggleStatus(obj, urlValue) {
	$(obj).attr('disabled', 'disabled');
	$.ajax({
		url: urlValue ,
		type:'GET',
		success: function(){
			$(obj).removeAttr('disabled');
		}
	});
}

</script>
{/literal}

<h1>Użytkownicy aplikacji</h1>

<table cellspacing="0" cellpadding="0" border="0">
	<tr class="selAllRow">
		<td class="cornerTop"></td><td colspan="5"><a href="#" class="selAll">Zaznacz wszystkie</a> <a href="#" onclick="return deleteObjects();">usuń</a> <a href="#" onclick="return blockObjects();">zablokuj</a></td>
	</tr>
	<tr>
		<td class="selAll">&nbsp;</td>
		<th>{tables type='header' label='Lp.' tid='users_table' noSort=noSort}{*<div style="float:left; width:100%">Lp.<div class="sort"><a class="ascendingAct" href="#">&nbsp;</a><a class="descending" href="#">&nbsp;</a></div></div>*}</th>
		<th>{tables type='header' label='Email' tid='users_table' o='email'}{*Email<div class="sort"><a class="ascendingAct" href="#">&nbsp;</a><a class="descending" href="#">&nbsp;</a></div>*}</th>
		<th>{tables type='header' label='Imię' tid='users_table' o = 'first_name'}</th>
		<th>{tables type='header' label='Nazwisko' tid='users_table' o = 'last_name'}</th>
		<th>{tables type='header' label='Status' tid='users_table' noSort=noSort}{*Status<div class="sort"><a class="ascendingAct" href="#">&nbsp;</a><a class="descending" href="#">&nbsp;</a></div>*}</th>
		<th>{tables type='header' label='Aktywny' tid='users_table' noSort=noSort}{*Aktywny<div class="sort"><a class="ascendingAct" href="#">&nbsp;</a><a class="descending" href="#">&nbsp;</a></div>*}</th>
		<th class="noSort"><a href="{url User=AddUser}" class="add">Dodaj</a> <div class="sort"><a class="ascendingAct" href="#">&nbsp;</a><a class="descending" href="#">&nbsp;</a></div></th>
	</tr>
	{foreach from=$list item=obj name=list}
	<tr>
		<td class="selAll"><input name="objs[]" value="{$obj->getId()}" id="remove_{$obj->getId()}" type="checkbox" /></td>
		<td>{tables type='lp' tid='users_table' iteration=$smarty.foreach.list.iteration}</td>
		<td>{$obj->getEmail()}</td>
		<td>{$obj->getFirstName()}</td>
		<td>{$obj->getLastName()}</td>
		<td><input type="checkbox" class="status" value="{$obj->getId()}" {if $obj->getStatus()}checked="checked"{/if} onchange="toggleStatus(this, '{url User=ToggleStatus id=$obj->getId()}')" /></td>
		<td><input type="checkbox" class="active" value="{$obj->getId()}" {if $obj->getActive()}checked="checked"{/if} onchange="toggleStatus(this, '{url User=ToggleActivate id=$obj->getId()}')" /></td>
		<td><a href="{url User=EditUser id=$obj->getId()}" class="edit">edytuj</a><a href="#" onclick="return confirmAction(this, '{url User=RemoveUser id=$obj->getId()}');" title="Czy na pewno usunąć użytkownika?" class="deleteNoAlert">usuń</a></td>
	</tr>
	{foreachelse}
	<tr>
		<td class="selAll"></td><td colspan="5" style="text-align: center; font-weight: bolder;">Lista jest pusta</td>
	</tr>
	{/foreach}
	<tr class="selAllRow">
		<td class="cornerBottom"></td><td colspan="6">
			<a href="#" class="selAll">Zaznacz wszystkie</a> <a href="#" onclick="return deleteObjects();">usuń</a> <a href="#" onclick="return blockObjects();">zablokuj</a>
			<div class="pager">
				{tables type='on_page' tid='users_table'}
				{tables type='pagination' tid='users_table' all_count=$c}
				
			</div>
		</td>
	</tr>
</table>

<div class="clearBoth"></div>